//
//  MJ_ReportTableViewCell.m
//  UEAssistant
//
//  Created by mac on 2018/1/5.
//  Copyright © 2018年 youyixinxi. All rights reserved.
//

#import "MJ_ReportTableViewCell.h"
#import "UIColor+Extend.h"
@interface MJ_ReportTableViewCell ()

@property (strong, nonatomic)UILabel * languageLabel;

@property (strong, nonatomic)UIButton *pullDownBtn;

@property (strong, nonatomic)UIView *line;


@property (strong, nonatomic)NSMutableArray *contentArray;
@end


@implementation MJ_ReportTableViewCell

- (UILabel *)languageLabel {
    if (!_languageLabel) {
        _languageLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 18, Screen_Width-60, 15)];
        _languageLabel.textColor = [UIColor colorWithHexString:@"#26292b"];
        _languageLabel.font = [UIFont systemFontOfSize:15];
        _languageLabel.text = @"简体中文→英文";
    }
    return _languageLabel;
}

- (UIView *)line
{
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:CGRectMake(15, 100, Screen_Width-30, 0.5)];
        _line.backgroundColor = [UIColor colorWithHexString:@"#eeeeee"];
    }
    return _line;
}

- (UIButton *)pullDownBtn {
    if (!_pullDownBtn) {
        _pullDownBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_pullDownBtn setImage:[UIImage imageNamed:@"下拉-1"] forState:UIControlStateNormal];
        _pullDownBtn.frame = CGRectMake(Screen_Width-42, 0, 42, 42);
        [_pullDownBtn addTarget:self action:@selector(pullDownBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    }
   return _pullDownBtn;
}

- (NSMutableArray *)contentArray {
    if (!_contentArray) {
        _contentArray = [NSMutableArray array];
    }
    return _contentArray;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.separatorInset = UIEdgeInsetsMake(0, 15, 0, 15);
        
        NSArray *titles = @[@"项目数",@"总字数",@"去重率",@"团队语料"];
        for (NSInteger i = 0; i < 4; ++ i) {
            
            UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15+i%4*((Screen_Width-30)/4.0), 49+i/4*64, (Screen_Width-30)/4.0, 15)];
            titleLabel.text = titles[i];
            titleLabel.textColor = [UIColor colorWithHexString:@"#999999"];
            titleLabel.font = [UIFont systemFontOfSize:12];

            UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(15+i%4*((Screen_Width-30)/4.0), 70+i/4*64, (Screen_Width-30)/4.0, 20)];
            contentLabel.text = [NSString stringWithFormat:@"%zd",i];;
            contentLabel.textColor = [UIColor colorWithHexString:@"#333333"];
            contentLabel.font = [UIFont systemFontOfSize:15];
            [self.contentArray addObject:contentLabel];
            [self.contentView addSubview:titleLabel];
            [self.contentView addSubview:contentLabel];
        }
        [self.contentView addSubview:self.languageLabel];
        [self.contentView addSubview:self.pullDownBtn];
    }
    return self;
}

- (void)setModel:(MJReportListModel *)model {
    _model = model;
    NSInteger wordCount = [model.wordcount integerValue];
    double quchonglv = (model.no_wordcount.floatValue +
                         model.dup_wordcount.floatValue +
                         model.selfpre_wordcount.floatValue +
                         model.sharepre_wordcount.floatValue)/(wordCount);
    NSString *lv = [NSString stringWithFormat:@"%.0f%%",round(quchonglv)*100];//去重率
    NSArray *content = @[model.project_count,
                         model.wordcount,
                         lv,
                         model.selfpre_wordcount];
    if (self.contentArray.count == 4) {
        self.languageLabel.text = model.language_pair;
        NSInteger index = 0;
        for (UILabel *label in self.contentArray) {
            label.text = content[index];
            index ++;
        }
    }

}

- (void)pullDownBtnPressed:(UIButton *)sender {

    [_delegate clickOpenWithCell:self];
}

@end
